package cli

import (
	"blockchain.com/part_5/block"
	"fmt"
	"strconv"
)

func (cli *CLI)PrintChain()  {
	bc := block.NewBlockchain("")
	defer bc.Db.Close()

	bci := bc.Iterator()
	for {
		block1 := bci.Next()

		fmt.Printf("============ Block %x ============\n", block1.Hash)
		fmt.Printf("Prev. block: %x\n", block1.PreBlockHash)

		pow := block.NewProofOfWork(block1)
		fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))

		for _,tx := range block1.Transactions{
			fmt.Println(tx)
		}

		fmt.Printf("\n\n")

		if len(block1.PreBlockHash) == 0 {
			break
		}
	}
}